home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / rhythmbox / plugins / jamendo / __init__.py next >
Encoding:
Python Source  |  2009-04-07  |  4.8 KB  |  141 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. # __init__.py
  4. #
  5. # Copyright (C) 2007 - Guillaume Desmottes
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11. #
  12. # The Rhythmbox authors hereby grant permission for non-GPL compatible
  13. # GStreamer plugins to be used and distributed together with GStreamer
  14. # and Rhythmbox. This permission is above and beyond the permissions granted
  15. # by the GPL license by which Rhythmbox is covered. If you modify this code
  16. # you may extend this exception to your version of the code, but you are not
  17. # obligated to do so. If you do not wish to do so, delete this exception
  18. # statement from your version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  28.  
  29. # Parts from "Magnatune Rhythmbox plugin" (stolen from rhythmbox's __init__.py)
  30. #     Copyright (C), 2006 Adam Zimmerman <adam_zimmerman@sfu.ca>
  31.  
  32. import rhythmdb, rb
  33. import gobject
  34. import gtk, gtk.glade
  35.  
  36. from JamendoSource import JamendoSource
  37. from JamendoConfigureDialog import JamendoConfigureDialog
  38.  
  39. popup_ui = """
  40. <ui>
  41.   <popup name="JamendoSourceViewPopup">
  42.     <menuitem name="AddToQueueLibraryPopup" action="AddToQueue"/>
  43.     <menuitem name="JamendoDownloadAlbum" action="JamendoDownloadAlbum"/>
  44.     <menuitem name="JamendoDonateArtist" action="JamendoDonateArtist"/>
  45.     <separator/>
  46.     <menuitem name="BrowseGenreLibraryPopup" action="BrowserSrcChooseGenre"/>
  47.     <menuitem name="BrowseArtistLibraryPopup" action="BrowserSrcChooseArtist"/>
  48.     <menuitem name="BrowseAlbumLibraryPopup" action="BrowserSrcChooseAlbum"/>
  49.     <separator/>
  50.     <menuitem name="PropertiesLibraryPopup" action="MusicProperties"/>
  51.   </popup>
  52. </ui>
  53. """
  54.  
  55.  
  56. class Jamendo(rb.Plugin):
  57.     #
  58.     # Core methods
  59.     #
  60.  
  61.     def __init__(self):
  62.         rb.Plugin.__init__(self)
  63.  
  64.     def activate(self, shell):
  65.         self.db = shell.get_property("db")
  66.  
  67.         self.entry_type = self.db.entry_register_type("JamendoEntryType")
  68.         # allow changes which don't do anything
  69.         self.entry_type.can_sync_metadata = True
  70.         self.entry_type.sync_metadata = None
  71.  
  72.         group = rb.rb_source_group_get_by_name ("stores")
  73.          if not group:
  74.              group = rb.rb_source_group_register ("stores",
  75.                                   _("Stores"),
  76.                                   rb.SOURCE_GROUP_CATEGORY_FIXED)
  77.  
  78.         theme = gtk.icon_theme_get_default()
  79.         rb.append_plugin_source_path(theme, "/icons/")
  80.  
  81.         width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)
  82.         icon = rb.try_load_icon(theme, "jamendo", width, 0)
  83.  
  84.         self.source = gobject.new (JamendoSource,
  85.                        shell=shell,
  86.                        entry_type=self.entry_type,
  87.                        plugin=self,
  88.                        icon=icon,
  89.                        source_group=group)
  90.         shell.register_entry_type_for_source(self.source, self.entry_type)
  91.         shell.append_source(self.source, None) # Add the source to the list
  92.  
  93.         # Add button
  94.         manager = shell.get_player().get_property('ui-manager')
  95.         action = gtk.Action('JamendoDownloadAlbum', _('_Download Album'),
  96.                 _("Download this album using BitTorrent"),
  97.                 'gtk-save')
  98.         action.connect('activate', lambda a: shell.get_property("selected-source").download_album())
  99.         self.action_group = gtk.ActionGroup('JamendoPluginActions')
  100.         self.action_group.add_action(action)
  101.         
  102.         # Add Button for Donate
  103.         action = gtk.Action('JamendoDonateArtist', _('_Donate to Artist'),
  104.                 _("Donate Money to this Artist"),
  105.                 'gtk-jump-to')
  106.         action.connect('activate', lambda a: shell.get_property("selected-source").launch_donate())
  107.         self.action_group.add_action(action)
  108.  
  109.         manager.insert_action_group(self.action_group, 0)
  110.         self.ui_id = manager.add_ui_from_string(popup_ui)
  111.         manager.ensure_update()
  112.  
  113.         self.pec_id = shell.get_player().connect('playing-song-changed', self.playing_entry_changed)
  114.  
  115.     def deactivate(self, shell):
  116.         manager = shell.get_player().get_property('ui-manager')
  117.         manager.remove_ui (self.ui_id)
  118.         manager.remove_action_group(self.action_group)
  119.         self.action_group = None
  120.  
  121.         shell.get_player().disconnect (self.pec_id)
  122.  
  123.         self.db.entry_delete_by_type(self.entry_type)
  124.         self.db.commit()
  125.         self.db = None
  126.         self.entry_type = None
  127.  
  128.         self.source.delete_thyself()
  129.         self.source = None
  130.  
  131.     def create_configure_dialog(self, dialog=None):
  132.         if not dialog:
  133.             glade_file = self.find_file("jamendo-prefs.glade")
  134.             dialog = JamendoConfigureDialog (glade_file).get_dialog()
  135.         dialog.present()
  136.         return dialog
  137.  
  138.     def playing_entry_changed (self, sp, entry):
  139.         self.source.playing_entry_changed (entry)
  140.  
  141.